/**
 * 单独执行的搜索命令
 */
const searchAliexpress = require('./search-fetch');
function printLine() {
  console.log('-------------------');
}
const readline = require('readline');

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});
console.clear();
if (process.argv[2]) {
  (async () => {
    const res = await searchAliexpress(process.argv[2], process.argv[3]);
    console.log(res);
  })();
} else {
  console.log('请输入两个参数，第一个参数是关键词，第二个参数是价格');
  printLine();

  rl.question('', async function (input) {
    let inputs=input.split(' ');
    const input1 = inputs[0];
    const input2 = inputs.length>1?inputs[1]:null;
    const res = await searchAliexpress(input1, input2);
    console.log(res);
    rl.close();
    process.exit();
  });
}
rl.on('SIGINT', () => {
  console.log('操作取消');
  rl.close();
});
